<?php

namespace app\api\model;

use think\Model;


class UserStore extends Model
{

    // 表名
    protected $table = 'tp_user_store';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'cat_name',
    ];

    public function getStoreImgAttr($value, $data){
        $value = $value ? $value : ($data['store_img'] ?? "");
        return unserialize($value);
    }
    public function getCatNameAttr($value, $data){
        $value = $value ? $value : ($data['cat_id'] ?? "");
        return UserStoreCat::where('cat_id',$value)->value('cat_name');
    }
    public function category(){
        return $this->hasMany('UserStoreCategory','store_id');
    }

    public function goods(){
        return $this->hasMany('ShopYiwu','shop_id')->limit(10);
    }
}
